<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
include 'thread.class.php';
include 'threadCollection.class.php';
class MyThread extends Thread
{
 public function run()
 {
  for (;;)
  {
   echo date('r')."\n";
   if (!$this->sleep(2)) {return;}
  }
 }
}
echo "Starting...\n";
$threads = new threadCollection;
for ($i = 0; $i < 5; ++$i) {$threads->push(new MyThread);}
$threads->start();
echo "Doing pseudo-job (sleep for 5 seconds)...\n";
sleep(5);
echo "Pseudo-job in master done. Stopping and waiting...\n";
$threads->stop();
$me = new Thread;
$me->collections = array($threads);
$me->waitAll();